using System.Configuration;
using System.Web.UI.WebControls;
using Microsoft.SharePoint.WebControls;
using System.Data;
using System;
using System.Collections;
using Microsoft.SharePoint;
using System.Diagnostics;

namespace CaptchaFieldControlSolution
{

    // custom field type uses helper class to initialize and render control
    public class CaptchaFieldControl : BaseFieldControl
    {
        public override string DisplayTemplateName
        {
            get { return @"MacawMastWss3TemplatesCaptchaControlDisplay"; }
        }

        public override object Value
        {
            get
            {
                EnsureChildControls();

                return null;
            }
            set
            {
                EnsureChildControls();
            }
        }

        protected override void CreateChildControls()
        {
            if (Field == null)
            {
                return;
            }

            base.CreateChildControls();

            if (ControlMode == SPControlMode.Display && ItemFieldValue != null)
            {
                string mlsfv = (string)ItemFieldValue;
                return;
            }
            Recaptcha.RecaptchaControl RecaptchaControl1 = new Recaptcha.RecaptchaControl();
            
            CaptchaField cf = (CaptchaField)Field;
            RecaptchaControl1.PrivateKey = cf.RecaptchaPrivateKey;
            RecaptchaControl1.PublicKey = cf.RecaptchaPublicKey;
            RecaptchaControl1.Theme = cf.RecaptchaTheme;
            RecaptchaControl1.Lang = SPContext.Current.Web.Locale.TwoLetterISOLanguageName;
            this.Controls.Add(RecaptchaControl1);
        }
    }
}
